<!DOCTYPE html>
<html>

	<head>
		<title>共享资料库</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../common/css/webfont.css">
		<link rel="stylesheet" href="../common/mui/mui.min.css">
		<link rel="stylesheet" href="../common/css/publicStyle.css">
		<link rel="stylesheet" href="fileList/fileListSub.css" />
		<meta charset="UTF-8">
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<div id="navimg" style="text-align: center;"><img src="../common/images/logo-white.png" width="130px"
					height="20px">
			</div>
		</header>
		<div class="mui-content web-font">
			<div id="slider" class="mui-slider mui-fullscreen">
				<div id="scroll" class="mui-slider-group">
					<div class="mui-slider-item mui-control-content mui-active">
						<div id="scroll0" class="mui-scroll-wrapper">
							<div class="mui-scroll">
								<ul id="scrollUl" class="mui-table-view mui-table-view-chevron"></ul>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script src="../common/mui/mui.min.js"></script>
		<script src="../common/js/h5adapter.js"></script>
		<script src="../common/js/localFileMethods.js"></script>
		<script src="../common/js/DHCMethods.js"></script>
		<script src="../common/js/app.js"></script>
		<script src="../common/js/globalSet.js"></script>
		<script src="../common/js/jquery-3.4.1.min.js"></script>
		<script src="../common/js/DHCWebService.js"></script>
		<script src="../common/mui/mui.pullToRefresh.js"></script>
		<script src="../common/mui/mui.pullToRefresh.material.js"></script>
		<script>
			var upPullElement = null;
			var start = 0,Limit = 20,category = -1
			var perInfo, TomcatUrl;
			var sourceData = []
			var urlStr = '';
			mui.init({
				swipeBack: false,
			});
			mui.plusReady(function() {
				plus.navigator.setStatusBarBackground('#24af96');
				plus.navigator.setStatusBarStyle('light');
				setup();
				mui.back = function() {
					plus.navigator.setStatusBarBackground('#fff')
					plus.navigator.setStatusBarStyle('dark');
					var _self = plus.webview.currentWebview();
					_self.close("auto");
				}
			});

			function setup() { //原来的mui.plusReady
				//				plus.navigator.setStatusBarBackground('white');
				//				plus.navigator.setStatusBarStyle('dark');
				var deceleration = mui.os.ios ? 0.003 : 0.0009;
				mui('.mui-scroll-wrapper').scroll({
					bounce: false,
					indicators: false, //是否显示滚动条
					deceleration: deceleration
				});

				var self = plus.webview.currentWebview();
				urlStr = self.urlStr;
				perInfo = app.getState()
				TomcatUrl = perInfo.TomcatUrl
				mui('#scrollUl').on('tap','li',itemTapped) 
				mui.each(document.querySelectorAll('.mui-slider-group .mui-scroll'), function(index, pullRefreshEl) {
					mui(pullRefreshEl).pullToRefresh({
						down: {
							callback: function() {
								pulldownRefresh(this, pullRefreshEl);
							}
						},
						up: {
							callback: function() {
								upPullElement = this;
								pullupRefresh(this);
							}
						}
					});
				});
				plus.nativeUI.showWaiting('正在加载');
				FindFileTree()
				mui('#slider').slider().stopped = true; //禁止左右滑动
			}

			
			var isPullUp = true;

			/*
			 * 上拉加载更多
			 */
			function pullupRefresh(endRefresh) {
				isPullUp = true;
				getFileListByCategory(endRefresh);
			}

			/*
			 * 下拉刷新列表
			 */
			function pulldownRefresh(endRefresh) {
				start = 0;
				sourceData = []
				mui('#scrollUl').off('tap','li',itemTapped) 
				mui('#scrollUl')[0].innerHTML = '';
				mui('#scrollUl').on('tap','li',itemTapped) 
				mui('#scroll0').scroll().scrollTo(0, 0, 100);
				isPullUp = false;
				if (upPullElement) {
					upPullElement.refresh(true);
				}
				getFileListByCategory(endRefresh);
			}

			function getFileListByCategory(endRefresh) {
				var pdict = {
					'par': category,
					'dateFlag': '0',
					'role': perInfo.maxRoleLevel,
					'appFlag': '1',
					'nurseid': perInfo['loginID'],
					'start': start,
					'limit': Limit
				} 
				var paramDict = {
					'method': 'web.INMOrgComm:FindFileTree',
					'params': JSON.stringify(pdict),
					'type': 'MethodNoFilter'
				}
				//console.log(JSON.stringify(pdict))
				mui.DHCWebService(paramDict, function(result) {
					// console.log(JSON.stringify(result))
					plus.nativeUI.closeWaiting();
					var arrary = result.data
					if (arrary.length == 0) {
						if (endRefresh != null) {
							if (isPullUp) {
								endRefresh.endPullUpToRefresh();
							} else {
								endRefresh.endPullDownToRefresh();
							}
						}
						mui.toast('当前分类下没有文件');
						return;
					}
					sourceData = sourceData.concat(arrary)
					updateUIs(arrary);
					if (endRefresh != null) {
						if (isPullUp) {
							endRefresh.endPullUpToRefresh(arrary.length < Limit);
						} else {
							endRefresh.endPullDownToRefresh();
						}
					}
					start += arrary.length
				}, function(error) {
					mui.toast(error);
					plus.nativeUI.closeWaiting();
					if (endRefresh != null) {
						if (isPullUp) {
							endRefresh.endPullUpToRefresh();
						} else {
							endRefresh.endPullDownToRefresh();
						}
					}
				});
			}

			/*
			 * 更新文件列表
			 */
			function updateUIs(dataArr) {
				var scroll1Ul = document.getElementById("scrollUl");
				for (var i = 0; i < dataArr.length; i++) {
					var oneCell = document.createElement('li');
					var dict = dataArr[i]
					var oneCell = document.createElement('li');
					scroll1Ul.appendChild(oneCell)
					
					oneCell.id = start + i
					oneCell.setAttribute('class', 'mui-table-view-cell public-flex-row');
					oneCell.setAttribute('data-id', dict['id']);
					var html = '<div class="pdfIcon"><img src="../dependence/home/images/folder-share.png" /></div>' +
						'<div class="mui-media-body"><div class="filenameStyle">' + dict.label + '</div>' +
						'<div class="rightOneLine">' +
						'<div class="totalSize"></div>' +
						'<div class="uploadTime">' + dict.CreateDate + '</div>' +
						'</div></div>'
					oneCell.innerHTML = html
				}
			}

			function itemTapped() {
				
				var navText = this.querySelector('.filenameStyle').innerText
				var folderName = urlStr+'/'+navText
				var id = this.getAttribute('data-id')
				var webview = mui.openWindow({
					url: "fileList/hulizhiyin.html",
					id: "hulizhiyin",
					extras: {
						category: folderName,
						navTitle: navText,
						pid:id,
						from:'share'
					}
				});
			}

			function FindFileTree() {
				var pdict = {
					'par': 0,
					'dateFlag': '0',
					role: perInfo.maxRoleLevel,
					'appFlag': '1',
					'nurseid': perInfo['loginID']
				}
				var paramDict = {
					'method': 'web.INMOrgComm:FindFileTree',
					'params': JSON.stringify(pdict),
					'type': 'MethodNoFilter'
				}
				//console.log(JSON.stringify(pdict))
				mui.DHCWebService(paramDict, function(result) {
					//console.log(JSON.stringify(result))
					if (result.msgcode == '1') {
						getPid(result.data)
						getFileListByCategory(null)
					} else {
						mui.toast(result.msg)
					}
				}, function(errorStr) {
					mui.toast(errorStr)
				});
			}

			function getPid(arr) {
				var pathArr = urlStr.split('/')
				var currArr = arr
				for (var i = 0; i < pathArr.length; i++) {
					var text = pathArr[i]
					for (var j = 0; j < currArr.length; j++) {
						var dict = currArr[j]
						if (dict.label == text) { //看看需要找下级不
							if (i == pathArr.length - 1) { //最后一层
								category = dict.id
							} else {
								currArr = dict.children
								if (currArr == undefined) {
									return
								}
							}
							break
						}
					}
				}
			}
		</script>
	</body>

</html>